package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sc.nft.entity.EcologyHatchMethodConf;
import com.sc.nft.entity.EcologyHatchRewardsConf;
import com.sc.nft.entity.EcologyHatchShareIncomeConf;
import com.sc.nft.entity.vo.ecology.HatchMethodCollectionVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.EcologyHatchMethodCollectionConf;
import com.sc.nft.mapper.EcologyHatchMethodCollectionConfMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * 生态-熔炼方式藏品关联表(sc_ecology_hatch_method_collection_conf)数据DAO
 *
 * @author Sun
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2024-06-07 09:04:10
 */
@Slf4j
@Repository
public class EcologyHatchMethodCollectionConfDao extends ServiceImpl<EcologyHatchMethodCollectionConfMapper, EcologyHatchMethodCollectionConf> {


    /**
     * 根据熔炼方式id和熔炼配置id获取列表
     *
     * @param methodId
     * @param ecologyHatchId
     * @return
     */
    public List<EcologyHatchMethodCollectionConf> getList(Long methodId, Long ecologyHatchId) {
        LambdaQueryWrapper<EcologyHatchMethodCollectionConf> wrapper = new LambdaQueryWrapper<>();
        if (Objects.nonNull(methodId)){
            wrapper.eq(EcologyHatchMethodCollectionConf::getMethodId, methodId);
        }
        wrapper.eq(EcologyHatchMethodCollectionConf::getEcologyHatchId, ecologyHatchId);
        return list(wrapper);
    }

    /**
     * 获取熔炼方式藏品关联表
     *
     * @param id
     * @param ecologyHatchId
     * @param methodId
     * @return
     */
    public EcologyHatchMethodCollectionConf getOne(Long id, Long ecologyHatchId, Long methodId) {
        LambdaQueryWrapper<EcologyHatchMethodCollectionConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchMethodCollectionConf::getId, id);
        wrapper.eq(EcologyHatchMethodCollectionConf::getEcologyHatchId, ecologyHatchId);
        wrapper.eq(EcologyHatchMethodCollectionConf::getMethodId, methodId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    /**
     * 修改
     *
     * @param collectionId
     * @param collectionName
     * @param expendCount
     * @param destroyCount
     * @return
     */
    public boolean updateById(Long id, Long collectionId, String collectionName, Integer expendCount, Integer destroyCount) {
        LambdaUpdateWrapper<EcologyHatchMethodCollectionConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchMethodCollectionConf::getId, id);
        wrapper.set(EcologyHatchMethodCollectionConf::getCollectionId, collectionId);
        wrapper.set(EcologyHatchMethodCollectionConf::getCollectionName, collectionName);
        wrapper.set(EcologyHatchMethodCollectionConf::getExpendCount, expendCount);
        wrapper.set(EcologyHatchMethodCollectionConf::getDestroyCount, destroyCount);
        return update(new EcologyHatchMethodCollectionConf(), wrapper);
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids) {
        LambdaUpdateWrapper<EcologyHatchMethodCollectionConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(EcologyHatchMethodCollectionConf::getId, ids);
        return remove(wrapper);
    }

    /**
     * 获取熔炼配置藏品关联表
     *
     * @param ecologyHatchId
     * @return
     */
    public List<HatchMethodCollectionVO> getHatchMethodCollectionVO(Long userId,Long ecologyHatchId) {
        return baseMapper.getHatchMethodCollectionVO(userId,ecologyHatchId);
    }

    public EcologyHatchMethodCollectionConf getOneByCollectionId(Long collectionId, Long methodId) {
        LambdaQueryWrapper<EcologyHatchMethodCollectionConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchMethodCollectionConf::getCollectionId, collectionId);
        wrapper.eq(EcologyHatchMethodCollectionConf::getMethodId, methodId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }


    public boolean updateIsMainById(Long id, Boolean isMain) {
        LambdaUpdateWrapper<EcologyHatchMethodCollectionConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyHatchMethodCollectionConf::getId, id);
        wrapper.set(EcologyHatchMethodCollectionConf::getIsMain, isMain);
        return update(new EcologyHatchMethodCollectionConf(), wrapper);
    }

    public List<EcologyHatchMethodCollectionConf> listByEcologyHatchIdAndIsMain(Long id) {
        LambdaQueryWrapper<EcologyHatchMethodCollectionConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyHatchMethodCollectionConf::getEcologyHatchId, id);
        wrapper.eq(EcologyHatchMethodCollectionConf::getIsMain, Boolean.TRUE);
        return list(wrapper);
    }
}